#pragma once
#include "mongoose.h"
#include <deque>
#include <string>
#include "HTTPResponse.h"

#define hs_request mg_request_info



//the max buffer len is 0x4000
class IHS
{
public:
	/*
		Write replay to user web,using variable param.
	*/
	virtual int hsWrite(const char *fmt, ...) = 0;
	/*
		Write replay to user web,using certain buffer.
	*/
	virtual int hsWriteBuf(const char *buf,int len) = 0;
	/*
		Helper to Write standard header to user web.
	*/
	virtual int hsWriteHeader(const char *header_type) = 0;
	virtual int hsWriteResponse(CResponse * pResponse) = 0;
	virtual int hsSendFile(const char *path) = 0;
	virtual mg_connection * getconn() = 0;
};

//[in]void* func == IHS interface,use IHS to reply data to client
typedef  int (*HsBindFunc)(void* func,const hs_request *buf);

void InitHttpServer();

// return value:
// -1: Init HTTP Server error.
// -2: Init HTTP Listen Port error.
int StartHttpServer(unsigned short port, const char * logfile);

void StopHttpServer();
void Bind(char* uri_regex,char* dllpath);
void BindDllFunction(char* uri_regex,char* dllpath,char* processname);
void BindFunction(char* uri_regex,HsBindFunc bindFunc);

//private:
void InitPlugin();
void DetachPlugin();

#ifdef __cplusplus
extern "C"
{
#endif
void StartHomeServer();
void StopHomeServer();

#ifdef __cplusplus
}
#endif


